package com.yunding.house.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunding.house.mapper.EstateMapper;
import com.yunding.house.pojo.Estate;
import com.yunding.house.service.EstateService;
import com.yunding.house.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 楼盘表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-08-14
 */
@Service
public class EstateServiceImpl implements EstateService {

    /**
     * CRUD
     */
    @Autowired
    private EstateMapper estateMapper;

    public void save(Estate estate) {
        estateMapper.insert(estate);
    }

    public void del(long id) {
        estateMapper.deleteById(id);
    }

    public void update(Estate estate) {
        estateMapper.updateById(estate);
    }

    public List<Estate> findAll() {
        return estateMapper.selectList(null);
    }

    /**
     * 条件分页查询
     *
     * @param page
     * @param size
     * @param estate
     * @return
     */
    public PageResult search(int page, int size, Estate estate) {
        //分页对象
        Page<Estate> page1 = new Page<Estate>(page, size);
        //条件对象
        QueryWrapper queryWrapper = new QueryWrapper(new Estate());
        //模糊查询name
        queryWrapper.like("name", estate.getName());
        IPage iPage = estateMapper.selectPage(page1, queryWrapper);
        return new PageResult(iPage.getTotal(), iPage.getRecords());
    }
}
